package org.example.service.impl;

import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import org.example.domain.po.ErpAccount;
import org.example.domain.po.ErpInOutItem;
import org.example.service.ErpAccountService;
import org.example.mapper.ErpAccountMapper;
import org.example.utils.Result;
import org.springframework.stereotype.Service;

import java.util.List;

/**
* @author 14120
* @description 针对表【erp_account(结算账户表)】的数据库操作Service实现
* @createDate 2024-10-30 08:58:51
*/
@Service
public class ErpAccountServiceImpl extends ServiceImpl<ErpAccountMapper, ErpAccount>
    implements ErpAccountService{
    public List<ErpAccount> findaccount(){
        return baseMapper.findaccount();
    }
    @Override
    public Page<ErpAccount> findByPage(Page<ErpAccount> page, String name, String accNumber, String remark, Long tenantId) {
        return baseMapper.findByPage(page, name, accNumber, remark, tenantId);
    }

    @Override
    public boolean modifyTheState(List<Integer> ids, String status) {
        return lambdaUpdate().set(ErpAccount::getStatus, status).in(ErpAccount::getAccId, ids).update();
    }

    @Override
    public boolean SetDefault(Integer accId) {
        String isDefault = baseMapper.findIsDefault();
        if (isDefault != null && isDefault.equals(String.valueOf(accId))){
            return true;
        }
        if (isDefault!=null){
            lambdaUpdate().set(ErpAccount::getIsDefault, false).in(ErpAccount::getAccId, isDefault).update();
        }
        boolean update = lambdaUpdate().set(ErpAccount::getIsDefault, true).in(ErpAccount::getAccId, accId).update();
        return update;
    }

}




